﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RegisterationCommon.Notice;
using RegisterationCommon.Student;

namespace RegisterationSystem.Space_Education
{
    public partial class notice_manage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                switch (Request.Form["action"])
                {
                    case "upd":
                        UpdNoticeList();
                        break;
                    case "updstatus":
                        UpdNoticeStatus();
                        break;
                    case "del":
                        DelNotice();
                        break;
                    case "updnotice":
                        UpdNotice();
                        break;

                }
            }
        }
        //修改公告信息
        void UpdNotice()
        {
            string id = Request.Form["id"];
            string status = Request.Form["status"];
            string tile = Request.Form["tile"];
            string count = Request.Form["count"];
            string rec = Request.Form["rec"];
            Notice n = new Notice();
            n.ID = Convert.ToInt32(id);
            n.Status = Convert.ToBoolean(Convert.ToInt32(status));
            n.Recrive = Convert.ToInt32(rec);
            n.Content = count;
            n.Tile = tile;
            n.UpdNotice();
        }
        //删除
        void DelNotice()
        {
            string id = Request.Form["id"];
            id = id.Substring(0, id.Length - 1);
            Notice n = new Notice();
            n.DelNoticeList(id);
        }
        //批量修改公告接受对象
        void UpdNoticeList()
        {
            string idlist = Request.Form["id"];
            string countlist = Request.Form["count"];
            string[] ids = idlist.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            string[] counts = countlist.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < ids.Length; i++)
            {
                Notice n = new Notice();
                n.ID = Convert.ToInt32(ids[i]);
                n.Recrive = Convert.ToInt32(counts[i]);
                n.UpdNoticeRecriveByID();
            }
        }
        //批量修改状态
        void UpdNoticeStatus()
        {
            string idlist = Request.Form["id"];
            string sid = Request.Form["sid"];
            string[] ids = idlist.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < ids.Length; i++)
            {
                Notice n = new Notice();
                n.ID = Convert.ToInt32(ids[i]);
                n.Status = Convert.ToBoolean(Convert.ToInt32(sid));
                n.UpdNoticeStatusByID();
            }
        }
    }
}